﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Service;
using MODEL;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
using Common;

namespace ViewModel.StationControl
{
    public class StationControlViewModel : ViewModelBase
    {
        public ICommand ControlCommand { get; set; }

        private IEnumerable<StationInfo> m_StationInfoList;
        public IEnumerable<StationInfo> StationInfoList
        {
            get { return this.m_StationInfoList; }
            set { this.m_StationInfoList = value; base.RaisePropertyChanged(() => StationInfoList); }
        }

        private IStationServcie m_StationService;

        public StationControlViewModel(IStationServcie stationService)
        {
            this.m_StationService = stationService;
            this.ControlCommand = new RelayCommand<StationInfo>(ShowControlForm);
            RefreshDate();
        }

        public async void RefreshDate()
        {
            StationInfoList = await this.m_StationService.QueryStationsAsync();
        }

        public void ShowControlForm(StationInfo stationInfo)
        {
            ValveControlViewModel vm = SimpleIoc.Default.GetInstanceWithoutCaching<ValveControlViewModel>();
            vm.StationInfo = stationInfo;
            this.MessengerInstance.Send<ViewModelBase>(vm, "ValveControl_ShowControlForm");
        }
    }
}
